package com.ruoyi.web.controller.technician;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.technician.domain.StoreTechnician;
import com.ruoyi.technician.service.IStoreTechnicianService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 技师信息Controller
 *
 * @author ch
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/technician/technician")
public class StoreTechnicianController extends BaseController
{
    @Autowired
    private IStoreTechnicianService storeTechnicianService;

    /**
     * 查询技师信息列表
     */
    @PreAuthorize("@ss.hasPermi('technician:technician:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreTechnician storeTechnician)
    {
        startPage();
        List<StoreTechnician> list = storeTechnicianService.selectStoreTechnicianList(storeTechnician);
        return getDataTable(list);
    }

    /**
     * 导出技师信息列表
     */
    @PreAuthorize("@ss.hasPermi('technician:technician:export')")
    @Log(title = "技师信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StoreTechnician storeTechnician)
    {
        List<StoreTechnician> list = storeTechnicianService.selectStoreTechnicianList(storeTechnician);
        ExcelUtil<StoreTechnician> util = new ExcelUtil<StoreTechnician>(StoreTechnician.class);
        return util.exportExcel(list, "技师信息数据");
    }

    /**
     * 获取技师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('technician:technician:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storeTechnicianService.selectStoreTechnicianById(id));
    }

    /**
     * 新增技师信息
     */
    @PreAuthorize("@ss.hasPermi('technician:technician:add')")
    @Log(title = "技师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreTechnician storeTechnician)
    {
        return toAjax(storeTechnicianService.insertStoreTechnician(storeTechnician));
    }

    /**
     * 修改技师信息
     */
    @PreAuthorize("@ss.hasPermi('technician:technician:edit')")
    @Log(title = "技师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreTechnician storeTechnician)
    {
        storeTechnician.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(storeTechnicianService.updateStoreTechnician(storeTechnician));
    }

    /**
     * 删除技师信息
     */
    @PreAuthorize("@ss.hasPermi('technician:technician:remove')")
    @Log(title = "技师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeTechnicianService.logicDeleteStoreTechnician(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
